package com.mida.app.knw.controller;

import com.mida.app.knw.service.DtDefineSpaceService;
import com.mida.dms.knw.entity.DtDefineSpace;
import com.mida.dms.knw.entity.vo.DtDefineSpaceConsumerVo;
import com.mida.dms.knw.entity.vo.DtDefineSpaceVo;
import com.mida.dms.knw.vo.PageResultVo;
import com.mida.dms.mdm.vo.provider.BaseOrgInfoVo;
import com.mida.tool.common.result.ActionResult;
import com.mida.tool.common.result.ListResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


@RestController
@RequestMapping("dtDefineSpace")
@CrossOrigin
@Slf4j
public class DtDefineSpaceController {
    @Autowired
    DtDefineSpaceService dtDefineSpaceService;

    /**
     * 1、添加定义空间
     *
     * @param dtDefineSpaceVo
     * @return
     */
    @PostMapping("add")
    public ActionResult add(@RequestBody DtDefineSpaceVo dtDefineSpaceVo) {
        return dtDefineSpaceService.add(dtDefineSpaceVo);
    }

    /**
     * 2、更新定义空间
     *
     * @param dtDefineSpaceVo
     * @return
     */
    @PostMapping(value = "update",consumes = {"application/json"})
    public ActionResult update(@RequestBody DtDefineSpaceVo dtDefineSpaceVo) {
        return dtDefineSpaceService.update(dtDefineSpaceVo);
    }

    /**
     * 3、删除定义空间
     *
     * @param defineSpaceSoid 定义空间soid
     * @return null
     */
    @GetMapping("delete")
    public ActionResult delete(@RequestParam("defineSpaceSoid") long defineSpaceSoid) {
        return dtDefineSpaceService.delete(defineSpaceSoid);
    }

    /**
     * 4、获取单个定义空间
     * @param defineSpaceSoid 定义空间soid
     * @return
     */
    @GetMapping("get")
    public ListResult<DtDefineSpaceVo> get(@RequestParam("defineSpaceSoid")long defineSpaceSoid) {
        return dtDefineSpaceService.get(defineSpaceSoid);
    }

    /**
     * 5、分页查询定义空间
     *
     * @param searChData  搜索关键字
     * @param currentPage 第几页
     * @param pageSize    每页显示数
     * @return
     */
    @GetMapping("findPage")
    public ListResult<PageResultVo<DtDefineSpaceVo>> findPage(@RequestParam(value = "searchData") String searChData,
                                                            @RequestParam(value = "currentPage") Long currentPage,
                                                            @RequestParam(value = "pageSize") Long pageSize) {
        return dtDefineSpaceService.findPage(searChData, currentPage, pageSize);
    }

    /**
     *6、定义空间名称重复性校验
     */
    @GetMapping(value = "/checkName")
    public ActionResult checkName(@RequestParam(value = "name", required = true) String name,
                                  @RequestParam(value = "defineSpaceSoid", required = false) Long defineSpaceSoid) {
        return dtDefineSpaceService.checkName(name,defineSpaceSoid);
    }

    /**
     *7、更改定义空间状态
     *
     * @param defineSpaceSoid 定义空间soid
     * @param status          状态soid
     * @return
     */
    @GetMapping("/updateStatus")
    public ActionResult updateStatus(@RequestParam(value = "status", required = true) Long status,
                                     @RequestParam(value = "defineSpaceSoid", required = true) Long defineSpaceSoid) {
        return dtDefineSpaceService.updateStatus(status, defineSpaceSoid);
    }

    /**
     * 8、查询所有定义空间
     * @param searchData  搜索关键字
     * @return
     */
    @GetMapping(value = "/findAll")
    public ListResult<List<DtDefineSpace>> findPage(@RequestParam(value = "searchData", required = false) String searchData) {
        return dtDefineSpaceService.findAll(searchData);
    }

    /**
     * 1、根据当前用户员工soid查询医院
     *
     * @return
     */
    @GetMapping(value = "/findHospitalByEmployeeSoid")
    ListResult<List<BaseOrgInfoVo>> findHospitalByEmployeeSoid(HttpServletRequest request){
       return dtDefineSpaceService.findHospitalByEmployeeSoid(request);
    }

    /**
     *3.1根据医院soid模糊查询当前医院下员工信息
     * @param search 检索条件:工号,名称,拼音码，五笔码，
     * @param orgInfoSoid 组织soid （医院soid）
     * @param orgInfoType 组织类型:集团-2585、医院-2586、科室-2587
     * @return
     */
    @GetMapping("/findEmployeeListByOrgSoid")
    public  ListResult<List<DtDefineSpaceConsumerVo>> findEmployeeListByOrgSoid(@RequestParam("orgInfoSoid")Long orgInfoSoid,
                                                                                @RequestParam("orgInfoType")Long orgInfoType,
                                                                                @RequestParam(value = "search",defaultValue = "")String search){
        return dtDefineSpaceService.findListByOrgSoid(orgInfoSoid, 2586L, search);
    }

}
